<template>
  <div>
    <div>
      <input placeholder="请输入教师姓名" v-model="T_name"/>
    </div>

    <div >
      <mt-button  type="default" @click="get_Courses">查询</mt-button>
    </div>

    <div>
      <p class="Week">周一</p>
      {{this.Mon_Cour.teacher}}
      {{this.Mon_Cour.courses}}
      {{this.Mon_Cour.week}}
      {{this.Mon_Cour.time}}
      {{this.Mon_Cour.addr}}
      {{this.Mon_Cour.mylass}}
    </div>

    <div>
      <p class="Week">周二</p>
      {{this.Tues_Cour.teacher}}
      {{this.Tues_Cour.courses}}
      {{this.Tues_Cour.week}}
      {{this.Tues_Cour.time}}
      {{this.Tues_Cour.addr}}
      {{this.Tues_Cour.mylass}}
    </div>

    <div>
      <p class="Week">周三</p>
      {{this.Wed_Cour.teacher}}
      {{this.Wed_Cour.courses}}
      {{this.Wed_Cour.week}}
      {{this.Wed_Cour.time}}
      {{this.Wed_Cour.addr}}
      {{this.Wed_Cour.mylass}}
    </div>

    <div>
      <p class="Week">周四</p>
          {{this.Thur_Cour.teacher}}
          {{this.Thur_Cour.courses}}
          {{this.Thur_Cour.week}}
          {{this.Thur_Cour.time}}
          {{this.Thur_Cour.addr}}
          {{this.Thur_Cour.mylass}}
    </div>

    <div>
      <p class="Week">周五</p>
      {{this.Fri_Cour.teacher}}
      {{this.Fri_Cour.courses}}
      {{this.Fri_Cour.week}}
      {{this.Fri_Cour.time}}
      {{this.Fri_Cour.addr}}
      {{this.Fri_Cour.mylass}}
    </div>

    <div>
      <p class="Week">周六</p>
      {{this.Sat_Cour.teacher}}
      {{this.Sat_Cour.courses}}
      {{this.Sat_Cour.week}}
      {{this.Sat_Cour.time}}
      {{this.Sat_Cour.addr}}
      {{this.Sat_Cour.mylass}}
    </div>

    <div>
      <p class="Week">周日</p>
      {{this.Sun_Cour.teacher}}
      {{this.Sun_Cour.courses}}
      {{this.Sun_Cour.week}}
      {{this.Sun_Cour.time}}
      {{this.Sun_Cour.addr}}
      {{this.Sun_Cour.mylass}}
    </div>
  </div>
</template>

<script>
  import { Button } from 'mint-ui';
  import { Field } from 'mint-ui';
  import axios from 'axios';
  import { MessageBox } from 'mint-ui';
  export default {
    name: "re-content",
    components:{
      MtField:Field,
      MtButton:Button
    },
    data:function () {
      return{
        time:null,
        introduction:'',
        title:'',

        S_Cources:[],
        T_name:'',
        //储存每天的课程
        Mon_Cour:[],
        Tues_Cour:[],
        Wed_Cour:[],
        Thur_Cour:[],
        Fri_Cour:[],
        Sat_Cour:[],
        Sun_Cour:[],
        //数据库对象
        teacher:'',
        courses:'',
        week:'',
        time:'',
        addr:'',
        school:'',
        college:'',
        department:'',
        professional:'',
        mylass:''
      }
    },
    methods:{
      btnChange:function () {
        this.time = null;
        this.introduction = '';
        this.title = '';
      },
      get_Courses:function () {
        console.log("hehe")
        var _this = this;
        axios.get('http://23.83.244.88:8080/schedule')
          .then(function (response) {
            console.log("hehe")
            console.log(response.data)
            console.log("haha")
            console.log("数据response的长度是：",response.data.length);
            for (var i = 0;i<response.data.length;i++){
              if(_this.equalsIgnoreCase(_this.T_name, response.data[i].teacher)){
                // console.log("查询到数据：",response.data[i])
                // _this.S_Cources=response.data[i];

                if(response.data[i].week=="Mon"){
                  console.log("查询到周一数据：",response.data[i])
                  _this.Mon_Cour = response.date[i]
                }
                if(response.data[i].week=="Tues"){
                  console.log("查询到周二数据：",response.data[i])
                  _this.Tues_Cour = response.date[i]
                }
                if(response.data[i].week=="Wed"){
                  console.log("查询到周三数据：",response.data[i])
                  _this.Wed_Cour = response.date[i]
                }
                if(response.data[i].week=="Thur"){
                  console.log("查询到周四数据：",response.data)
                  // _this.Thur_Cour = response.date[i]
                  _this.Thur_Cour = response.data[i]
                  console.log("查询到周四数据：",response.data[i].teacher)
                }
                if(response.data[i].week=="Fri"){
                  console.log("查询到周五数据：",response.data[i])
                  _this.Fri_Cour = response.date[i]
                }
                if(response.data[i].week=="Sat"){
                  console.log("查询到周六数据：",response.data[i])
                  _this.Sat_Cour = response.date[i]
                }
                if(response.data[i].week=="Sun"){
                  console.log("查询到周日数据：",response.data[i])
                  _this.Sun_Cour = response.date[i]
                }
              }else {
                if((i == response.data.length-1)&&(_this.S_Cources.length==0)){
                  MessageBox('输入的查询条件错误，请重新输入');
                  _this.Input_agin();
                }
              }
            }
            // console.log(_this.S_Cources)
            console.log("周一：",_this.Mon_Cour)
            console.log("周二：",_this.Tues_Cour)
            console.log("周三：",_this.Wed_Cour)
            console.log("周四：",_this.Thur_Cour)
            console.log("周五：",_this.Fri_Cour)
            console.log("周六：",_this.Sat_Cour)
            console.log("周日：",_this.Sun_Cour)
          })
          .catch(function (error) {
            console.log(error);
          });

      },
      // get_Courses:function () {
      //   var _this = this
      //   axios.get('http://23.83.244.88:8080/schedule',{
      //     params:{
      //       teacher:_this.T_name
      //     }
      //   }).then(function (res) {
      //     console.log(res.data)
      //   }).catch(function (error) {
      //     console.log("请求出错")
      //   });
      // },
      equalsIgnoreCase:function (str1,str2) {
        if(str1.toUpperCase() == str2.toUpperCase())
        {
          return true;
        }
        return false;
      },
      Input_agin:function () {
        this.T_name = null
      }
    }
  }
</script>

<style scoped>
  .Week{

  }
  .set-button1{
    margin-top: 1rem;
    margin-left: 0rem;
    margin-right: 6.5rem;

  }
  .set-button1{
    margin-top: 1rem;
    margin-right: 3rem;
  }
</style>
